package com.ruoyi.web.controller.dgw;

import java.util.List;
import java.util.Map;

import com.ruoyi.dgw.domain.CowShed;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.CowEssen;
import com.ruoyi.dgw.service.ICowEssenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 牛信息Controller
 *
 * @author ruoyi
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/dgw/cowEssen")
@Slf4j
public class CowEssenController extends BaseController
{
    @Autowired
    private ICowEssenService cowEssenService;

    /**
     * 查询牛信息列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:cowEssen:list')")
    @GetMapping("/list")
    public TableDataInfo list(CowEssen cowEssen)
    {
        startPage();
        List<CowEssen> list = cowEssenService.selectCowEssenList(cowEssen);
        return getDataTable(list);
    }

    /**
     * 导出牛信息列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:cowEssen:export')")
    @Log(title = "牛信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CowEssen cowEssen)
    {
        List<CowEssen> list = cowEssenService.selectCowEssenList(cowEssen);
        ExcelUtil<CowEssen> util = new ExcelUtil<CowEssen>(CowEssen.class);
        return util.exportExcel(list, "牛信息数据");
    }

    /**
     * 获取牛信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:cowEssen:query')")
    @GetMapping(value = "/{cowEssenId}")
    public AjaxResult getInfo(@PathVariable("cowEssenId") String cowEssenId)
    {
        return AjaxResult.success(cowEssenService.selectCowEssenByCowEssenId(cowEssenId));
    }

    /**
     * 新增牛信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:cowEssen:add')")
    @Log(title = "牛信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CowEssen cowEssen)
    {
        return toAjax(cowEssenService.insertCowEssen(cowEssen));
    }

    /**
     * 修改牛信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:cowEssen:edit')")
    @Log(title = "牛信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CowEssen cowEssen)
    {
        return toAjax(cowEssenService.updateCowEssen(cowEssen));
    }

    /**
     * 删除牛信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:cowEssen:remove')")
    @Log(title = "牛信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cowEssenIds}")
    public AjaxResult remove(@PathVariable String[] cowEssenIds)
    {
        return toAjax(cowEssenService.deleteCowEssenByCowEssenIds(cowEssenIds));
    }

    @PreAuthorize("@ss.hasPermi('dgw:cowEssen:list')")
    @GetMapping("/queryUser")
    public TableDataInfo queryUser(String nickName, String deptName){
        startPage();
        List<Map<String,String>> list= cowEssenService.queryUser(nickName,deptName);
        return getDataTable(list);
    }

    @GetMapping("/get/cow/count")
    public Map<String,Long> queryCountCow(){
        Map<String, Long> map = cowEssenService.queryCountCow();
        return map;
    }
}
